import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:wu_you/res/colors.dart';
import 'package:wu_you/utils/utils.dart';

class DialogGeneral extends StatefulWidget {
  final Widget child;
  final String title;
  final double minHeight;
  final EdgeInsetsGeometry padding;
  final double titleHeight;
  const DialogGeneral(
      {Key key, @required this.child, @required this.title, this.minHeight = 330, this.padding,this.titleHeight = 45})
      : assert(child != null),
        super(key: key);

  @override
  _DialogGeneralState createState() => _DialogGeneralState();
}
  class _DialogGeneralState extends State<DialogGeneral> {
  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
          borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
          color: Colors.white),
      height: widget.minHeight,
      child: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          Container(
            width: double.infinity,
            height: widget.titleHeight,
            child: Stack(
              children: [
                Positioned(
                    left: 10,
                    right: 40,
                    top: 0,
                    bottom: 0,
                    child: Container(
                      alignment: Alignment.center,
                      child: Text(
                        widget.title,
                        textAlign: TextAlign.center,
                        style:
                            TextStyle(color: AppColors.textColor, fontSize: 15),
                      ),
                    )),
                Positioned(
                    right: 0,
                    top: 0,
                    bottom: 0,
                    width: 44,
                    child: CloseButton()),
              ],
            ),
          ),
          Divider(),
          Expanded(
              child: Container(
            padding: widget.padding ?? EdgeInsets.only(left: 14, right: 14),
            width: double.infinity,
            child: widget.child,
          )),
        ],
      ),
    );
  }
}

class PrivacyDialog extends StatelessWidget {
  const PrivacyDialog(
      {Key key,
      this.backgroundImageStr,
      this.headerImgStr,
      this.title,
      this.content,
      this.contentPadding,
      this.actions,
      this.leftToRight = true})
      : super(key: key);
  final String backgroundImageStr;
  final String headerImgStr;
  final String title;
  final Widget content;
  final EdgeInsetsGeometry contentPadding;
  final List<Widget> actions;
  final bool leftToRight;

  @override
  StatelessElement createElement() {
    return super.createElement();
  }

  @override
  Widget build(BuildContext context) {
    return Dialog(
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(10)
      ),
      backgroundColor: Colors.white,
      child: Stack(
        children: [
          Visibility(
              child: this.backgroundImageStr != null
                  ? Image.asset(Utils.getImgPath(this.backgroundImageStr))
                  : SizedBox(
                      height: 0,
                    )),
          Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              Visibility(
                  child: this.headerImgStr != null
                      ? Image.asset(Utils.getImgPath(this.headerImgStr))
                      : SizedBox(
                          height: 0,
                        )),
              Visibility(
                child: title == null
                    ? SizedBox(
                        height: 0,
                      )
                    : Padding(
                        padding: contentPadding ??
                            EdgeInsets.only(left: 8,right: 8,top: 15),
                        child: Text(
                          title,
                          style: TextStyle(
                              color: AppColors.textColor, fontSize: 16),
                        )),
              ),
              Padding(
                  padding:
                      contentPadding ?? EdgeInsets.only(left: 8,right: 8,top: 15,bottom: 10),
                  child: content ??
                      Text(
                        "d得到我电脑快我脑壳未付款窝囊废服务费去发起网络法兰球阀分期垃圾分类",
                        style: TextStyle(
                            color: AppColors.textSecondaryColor, fontSize: 14),
                      )),
              leftToRight
                  ? Row(
                      mainAxisAlignment: MainAxisAlignment.spaceAround,
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: actions ??
                          [
                            TextButton(onPressed: () {}, child: Text("确定")),
                            TextButton(onPressed: () {}, child: Text("取消"))
                          ],
                    )
                  : Column(
                      mainAxisAlignment: MainAxisAlignment.spaceAround,
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: actions ??
                          [
                            TextButton(onPressed: () {}, child: Text("确定")),
                            TextButton(onPressed: () {}, child: Text("取消"))
                          ])
            ],
          ),
        ],
      ),
    );
  }

  void show(BuildContext context) async{
    Future.delayed(Duration(milliseconds: 200)).then((value) {
      showDialog(
          context: context,
          barrierDismissible: false,
          builder: (context) {
            return this;
          });

    });
  }
}
